asyncapi: '3.0.0'
info:
  title: Notifications Services
  version: '1'
  description: |
    AsyncAPI definition for notifications services in the banking system.
    This includes both notifications-api and notifications-builder services that consume
    various events from the system to trigger notifications and maintain notification projections.

    :::warning
    Please note that all the *Commands* and *Events* are wrapped into *Envelope* before being dispatched via Channels.
    :::

    Specific properties that are present in the metadata section of the envelope varied per message.
    The list of required metadata properties is provided in the header's documentation of the corresponding message.

    See this <Link href="/docs/index.html">page</Link> for the more details on the *Envelope* structure and other cross-cutting concerns.

defaultContentType: application/avro

servers:
  kafka:
    host: localhost:9092
    protocol: kafka

operations:
  # events consumed
  DeviceLoggedOut:
    action: receive
    channel:
      $ref: '#/channels/authentication.event.device-logged-out'

  DeviceRemoved:
    action: receive
    channel:
      $ref: '#/channels/authentication.event.device-removed'

channels:
  authentication.event.device-logged-out:
    address: authentication.event.device-logged-out
    x-eventcatalog-role: consumer
    messages:
      DeviceLoggedOutEvent:
        $ref: '#/components/messages/DeviceLoggedOutEvent'

  authentication.event.device-removed:
    address: authentication.event.device-removed
    x-eventcatalog-role: consumer
    messages:
      DeviceRemovedEvent:
        $ref: '#/components/messages/DeviceRemovedEvent'

components:
  messages:
    # Events
    DeviceLoggedOutEvent:
      name: DeviceLoggedOut
      title: Device Logged Out Event
      summary: Event emitted when a user's device has logged out
      description: |
        Consumed by notifications-api to delete push notification registration tokens from Redis.
        Also consumed by notifications-builder via wildcard event pattern.
      x-eventcatalog-message-type: event
      payload:
        $ref: '#/components/schemas/DeviceLoggedOut'

    DeviceRemovedEvent:
      name: DeviceRemoved
      title: Device Removed Event
      summary: Event emitted when a device is removed from a user's account
      description: |
        Consumed by notifications-builder via wildcard event pattern to clean up device-related projections.
      x-eventcatalog-message-type: event
      payload:
        $ref: '#/components/schemas/DeviceRemoved'

  schemas:
    DeviceLoggedOut:
      schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
      schema:
        $ref: './DeviceLoggedOut.avsc'

    DeviceRemoved:
      schemaFormat: 'application/vnd.apache.avro;version=1.9.0'
      schema:
        $ref: './DeviceRemoved.avsc'